import colorsys

import DolphinGame


def hsv_to_rgb(h, s, v):
    """Convert HSV to RGB color space."""
    return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h, s, v))


if __name__ == '__main__':
    DolphinGame.init()
    window = DolphinGame.Window()
    window.creat_window()

    hue = 0.0  # 初始色相
    running = True
    while running:
        for event in DolphinGame.get():
            if event.type == DolphinGame.QUIT:
                running = False
            if event.type == DolphinGame.KEYDOWN:
                if event.key == DolphinGame.K_q:
                    running = False

        # 更新色相
        hue += 0.001  # 调整这个值来改变过渡速度
        if hue > 1.0:
            hue -= 1.0  # 确保色相在 0 到 1 之间循环

        # 将 HSV 转换为 RGB
        current_color = hsv_to_rgb(hue, 1.0, 1.0)

        # 用更新后的颜色填充窗口
        window.fill(color=current_color)
        DolphinGame.flip()
